import {Actor, Action} from 'iflux2';
import {GoodsAddedType} from '../constant/action-type';
import {fromJS, OrderedSet} from 'immutable';

const defaultPagination = {
    pageSize: 10,
    pageNum:1,
    totalCount: 0
};


export default class GoodsAddedActor extends Actor {
    defaultState() {
        return {
            goodsAddedList: [],
            selectedRowKeys: OrderedSet(),
            pagination: defaultPagination,
            keyWords: ''
        }
    }


    @Action(GoodsAddedType.SET_LIST)
    setList(state, list) {
        return state.set('goodsAddedList', list);
    }


    @Action(GoodsAddedType.SET_PAGINATION)
    setPagination(state, page) {
        return state.update('pagination', (pagination)=>pagination.merge(page))
    }


    @Action(GoodsAddedType.RESET_PAGINATION)
    resetPagination(state) {
        return state.set('pagination', fromJS(defaultPagination));
    }


    @Action(GoodsAddedType.SET_KEYWORDS)
    setKeyWords(state, keyWords) {
        return state.set('keyWords', keyWords);
    }


    @Action(GoodsAddedType.SET_SELECTED_KEYS)
    setSelectedKeys(state, rowKeys) {
        return state.set('selectedRowKeys', rowKeys);
    }


    @Action(GoodsAddedType.RESET_SELECTED_KEYS)
    restSelectedKeys(state) {
        return state.set('selectedRowKeys', OrderedSet());
    }
}